<?php
class SearchRelation extends AppModel {

	var $name = 'SearchRelation';

	//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
	var $belongsTo = array(
			'User' => array('className' => 'User',
								'foreignKey' => 'user_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			)
	);
*/


	function getData($uid) {
		$c = array('user_id'=>$uid);
		$f = array();
		if (!$this->hasAny($c)) {
			$this->save($c);
		}
		$data = $this->find('first', array('conditons'=>$c, 'fields'=>$f));
		if (!empty($data[$this->name]['relations'])) {
			$data[$this->name]['relations'] = explode(';', $data[$this->name]['relations']);
		}
		return $data;
	}

	function saveSearchRelation($data) {
		if (!empty($data['relations'])) {
			$data['relations'] = implode(';', $data['relations']);
		} else {
			$data['relations'] = '';
		}
		return $this->save($data);
	}

	function getConditions($uid) {
		$return = false;
		$data = $this->getData($uid);
		if (!empty($data[$this->name]['relations'])) {
			$return['Soctypesrel.socrelation_id'] = $data[$this->name]['relations'];
		}
		return $return;
	}


	function getSearchRelationID($uid) {
		return $this->field('id', array('user_id'=>$uid));
	}


}
?>
